package com.yangfan.thread.thread_wangwenjun17;

import java.util.Random;


/**
 * 搬运工线程  往流水线上进行  搬运  商品
 */
public class TransportThread extends Thread {
    private final Channel channel;

    private static final Random random = new Random(System.currentTimeMillis());

    public TransportThread(String name, Channel channel) {
        super(name);
        this.channel = channel;
    }

    @Override
    public void run() {
        try {
            for (int i = 0; true; i++) {
                Request request = new Request(getName(), i);//自己构建一个商品
                this.channel.put(request);//加到传送带里面
                Thread.sleep(random.nextInt(1_000));//每次搬运的速度有快又慢
            }
        } catch (Exception e) {
        }
    }
}